const { Menu, BrowserWindow } = require('electron')
const remote = require('electron').remote

module.exports = mainWindow => {
  return {
    label: '进程管理',
    submenu: [
      createProcessSubMenu('进程状态转换', 'state-transition'),
      createProcessSubMenu('生产者消费者问题', 'producer-consumer'),
      createProcessSubMenu('进程调度', 'scheduler'),
    ],
  }
}

function createProcessSubMenu(label, url) {
  return {
    label,
    click: () => {
      const fullUrl =
        process.env.NODE_ENV === 'development'
          ? `http://localhost:8080/#/process/${url}`
          : `file://${__dirname}/index.html#/process/${url}`
      const processWindow = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
          nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION,
        },
      })
      // Menu.setApplicationMenu(null)
      processWindow.removeMenu()
      processWindow.loadURL(fullUrl)
      processWindow.webContents.openDevTools({ mode: 'right' })
    },
  }
}
